<template>
	<view class="content">
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">数据审核</block>
			<block slot="right">
				<view style="color: #fff;margin-right: 20rpx;" @click="shenhe">审核</view>
			</block>
		</cu-custom>
		<scroll-view scroll-y class="page">
			<view style="height: 10rpx;"></view>
			<view class="cu-list menu card-menu margin-bottom-xl shadow-lg radius " style="background-color: #fff;">
				<view class="u-header"><text class="tips">样品编号:</text><text class="val">{{data.sampleCode}}</text></view>
				<view class="u-body">
					<view class="row">
						<view class="tips">样品重量（kg）</view>
						<view class="val">{{data.sampleWeight}}</view>
					</view>
					<view class="row">
						<view class="tips">采样人</view>
						<view class="val">{{data.getSampleUname}}</view>
					</view>
					<view class="row">
						<view class="tips">采样时间</view>
						<view class="val">{{data.getSampleTime|timeStamp2}}</view>
					</view>
				</view>
			</view>
			
			
			<view v-for="item in data.sampleSubList" class="cu-list menu card-menu margin-bottom-xl shadow-lg radius " style="background-color: #fff;">
				<view class="u-header"><text class="tips">子样编号:</text><text class="val">{{item.sampleSubCode}}</text></view>
				<view class="u-body">
					<view class="row">
						<view class="tips">子样重量(kg)</view>
						<view class="val">{{item.sampleSubWeight}}</view>
					</view>
					<view class="row">
						<view class="tips">备注</view>
						<view class="val">{{item.note}}</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="cu-modal bottom-modal" :class="modalName=='confirm'?'show':''" @tap="hideModal">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white">
					<view class="action text-blue" @tap="pass(0)">驳回</view>
					<view class="action text-green" @tap="pass(1)">通过</view>
				</view>
				<view style="height: 200rpx;font-size: 30rpx;">
					<view class="inputbox">
						<text class="lg cuIcon-edit"></text>
						<input class="f_input" placeholder="拒绝理由" v-model="param.opinion" />
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				modalName: null,
				data: {},
				checkbox: [],
				param: {
					todoIds: [],
					opinion: ''
				}
			}
		},
		components: {},
		onShow() {
			this.data = uni.getStorageSync("AUDIT_DATA");
			this.param.todoIds.push(this.data.todoId);
			this.param.opinion ="";
			console.info(this.data);
		},
		methods: {
			shenhe: function() {
				this.modalName = "confirm";
			},
			hideModal: function() {
				this.modalName = null;
			},
			pass: function(f) {
				if (f == 1) {
					this.param.status = 202;
				} else {
					this.param.status = 203;
				}
				uni.request({
					url: this.$http + '/biz/bizSample/approve',
					data: this.param,
					header: {
						token: uni.getStorageSync("token")
					},
					method: 'POST',
					success: (res) => {
						if (res.statusCode == 200 && res.data.code == 0) {
							this.modalName = null;
							uni.showToast({
								icon: 'none',
								title: '操作成功！'
							});
							uni.navigateBack();
						} else {
							uni.showToast({
								icon: 'none',
								title: '操作失败，请重试！'
							});
						}
					},
					fail: function() {
						uni.showToast({
							icon: 'none',
							title: '服务器请求超时！'
						});
					}
				});

			},
			ChooseCheckbox(e) {
				let items = this.checkbox;
				let values = e.currentTarget.dataset.value;
				for (let i = 0, lenI = items.length; i < lenI; ++i) {
					if (items[i].itemCode == values) {
						items[i].checked = !items[i].checked;
						break
					}
				}
			}
		},
		filters: {
			timeStamp: function(value) {
				if (!value) return '';
				var now = new Date(value);
				console.log("time:" + JSON.stringify(now));
				var year = now.getFullYear();
				var month = now.getMonth() + 1;
				if (month < 10) {
					month = '0' + month
				}
				var date = now.getDate();
				if (date < 10) {
					date = '0' + date
				}
				return year + "-" + month + "-" + date
			},
			timeStamp2: function(value) { //具体到时分秒
				var date = new Date(value); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
				var year = date.getFullYear();
				var month = ("0" + (date.getMonth() + 1)).slice(-2);
				var sdate = ("0" + date.getDate()).slice(-2);
				var hour = ("0" + date.getHours()).slice(-2);
				var minute = ("0" + date.getMinutes()).slice(-2);
				var second = ("0" + date.getSeconds()).slice(-2);
				// 拼接
				var result = year + "-" + month + "-" + sdate + " " + hour + ":" + minute + ":" + second;
				// 返回
				return result;
			}
		}
	}
</script>

<style lang="scss">
	.inputbox {
		margin: 0 auto;
		width: 700rpx;
		height: 80rpx;
		border: 1px #D0D0D0 solid;
		border-radius: 10rpx;
		font-size: 30rpx;
		color: #116AB7;
		line-height: 80rpx;
		padding-left: 20.41rpx;
		display: flex;
		margin-top: 10rpx;
	}
	
	.f_input {
		text-align: left;
		width: 500rpx;
		height: 50rpx;
		margin-left: 20.83rpx;
		margin-top: 15rpx;
	}
	
	.selectbox {
		margin: 0 auto;
		width: 700rpx;
		height: 80rpx;
		border-radius: 10rpx;
		font-size: 30rpx;
		color: #116AB7;
		line-height: 80rpx;
		display: flex;
		margin-top: 10rpx;
		justify-content: space-between;
	}
</style>
